import request from '@/utils/request'

/**
 * 获取队伍通知列表
 * @param {number} teamId - 队伍ID
 * @returns {Promise} API响应
 */
export const getTeamNotificationsService = (teamId) => {
  return request({
    url: `/notifications/team/${teamId}`,
    method: 'GET'
  })
}

/**
 * 发布通知
 * @param {Object} notificationData - 通知数据
 * @param {number} notificationData.teamId - 队伍ID
 * @param {string} notificationData.title - 通知标题
 * @param {string} notificationData.content - 通知内容
 * @param {string} [notificationData.link] - 相关链接（可选）
 * @param {Array} [notificationData.images] - 图片数组（可选）
 * @returns {Promise} API响应
 */
export const publishNotificationService = (notificationData) => {
  // 转换数据格式以匹配后端VO
  const requestData = {
    teamId: notificationData.teamId,
    title: notificationData.title,
    content: notificationData.content,
    link: notificationData.link || null,
    imageUrls: notificationData.images ? notificationData.images.map(img => img.url) : []
  }

  return request({
    url: '/notifications/publish',
    method: 'POST',
    data: requestData
  })
}

/**
 * 获取通知详情
 * @param {number} notificationId - 通知ID
 * @returns {Promise} API响应
 */
export const getNotificationDetailService = (notificationId) => {
  return request({
    url: `/notifications/${notificationId}`,
    method: 'GET'
  })
}

/**
 * 删除通知
 * @param {number} notificationId - 通知ID
 * @returns {Promise} API响应
 */
export const deleteNotificationService = (notificationId) => {
  return request({
    url: `/notifications/${notificationId}`,
    method: 'DELETE'
  })
}

/**
 * 确认通知
 * @param {Object} confirmData - 确认数据
 * @param {number} confirmData.notificationId - 通知ID
 * @param {string} [confirmData.remark] - 备注（可选）
 * @returns {Promise} API响应
 */
export const confirmNotificationService = (confirmData) => {
  return request({
    url: '/notifications/confirm',
    method: 'POST',
    data: confirmData
  })
}

/**
 * 上传图片
 * @param {FormData} formData - 图片文件数据
 * @returns {Promise} API响应
 */
export const uploadImageService = (formData) => {
  return request({
    url: '/upload/image',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 删除文件
 * @param {string} fileUrl - 文件URL
 * @returns {Promise} API响应
 */
export const deleteFileService = (fileUrl) => {
  return request({
    url: '/upload/file',
    method: 'DELETE',
    params: { fileUrl }
  })
}